package com.read.controller;

import com.read.dto.result.JwtUserDto;
import com.read.util.JwtUtil;
import com.read.util.StringUtil;

import javax.servlet.http.HttpServletRequest;

/**
 * @author sh-sunb6
 * @description
 * @date 2019-01-14 16:21
 */
public class BaseController {

    /**
     * @description 获取用户信息
     * @author sh-sunb6
     * @date 2019-01-14 16:23
     */
    public JwtUserDto getUserInfo(HttpServletRequest request) {
        String token = request.getHeader("Authorization");// 从 http 请求头中取出 token

        if (!StringUtil.isNotEmpty(token)) {
            token = request.getParameter("Authorization");
        }

        JwtUserDto jUser = null;
        if (null != token && StringUtil.isNotEmpty(token)) {
            jUser = JwtUtil.getUserInfo(token);
        }

        return jUser;
    }

}
